@extends("layout.admin")

@section("title")
    考场列表
@endsection

@section("content")
    <div class="layui-card-body ">
        {{--搜索--}}
        <form class="layui-form layui-col-space5 layui-input-inline" id="search-form">
            <div class="demoTable">
                <div class="layui-inline">
                    <input type="text" class="layui-input" name="id" value="{{request('id')}}"  placeholder="请输入考场ID">
                </div>
                <div class="layui-inline" id="test6">
                    <input type="text" class="layui-input" name="keyword" value="{{request('keyword')}}"  placeholder="请输入关键字">
                </div>
                <div class="layui-inline">
                    <div id="index_category_id" style="width: 240px"></div>
                </div>
                <div class="layui-inline">
                    <input type="hidden" name="index_org_code" id="index_org_code" value="">
                    <div id="index_org_id"  style="width: 240px"></div>
                </div>
                <div class="layui-inline layui-show-xs-block">
                    <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
        </form>
    </div>
    {{--列表--}}
    <div class="layui-card-body ">
        <script type="text/html" id="toolbar">
            <div class="layui-btn-container">
                @if(_can('admin.basic.create'))
                    <a class="layui-btn layui-btn-sm" onclick="admin.openLayerForm('{{route("admin.basic.create")}}', '添加考场', 'POST', '700px', '90%')"><i class="layui-icon"></i>添加考场</a>
                @endif
                @if(_can('admin.basic.destroy'))
                    <a class="layui-btn layui-btn-sm layui-btn-danger" onclick="getDelIds()"><i class="layui-icon layui-icon-delete"></i>批量删除</a>
                @endif
            </div>
        </script>
        <table lay-filter="table-hide" style="display: none"  id="demo" lay-data="{height:'full-310', cellMinWidth: 80,toolbar: '#toolbar',defaultToolbar:['filter'],limit:{{$data['per_page']}}}">
            <thead>
            <tr>
                <th lay-data="{width:80,type:'checkbox',field:'id'}"></th>
                <th lay-data="{field:'basic',width:500}">考场名称</th>
                <th lay-data="{field:'category_name'}">考试科目</th>
                <th lay-data="{field:'org_name'}">组织机构</th>
                <th lay-data="{field:'status'}">状态</th>
                <th lay-data="{field:'created_at',hide:true}">创建时间</th>
                <th lay-data="{field:'updated_at',hide:true}">更新时间</th>
                <th lay-data="{field:'op',fixed: 'right', align:'center',toolbar: '#buttons'}">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($data['data'] as $vo)
                <tr>
                    <td>{{$vo['id']}}</td>
                    <td>[{{ $vo['id'] }}] {{ $vo['basic'] }}</td>
                    <td>{{ $vo['category_name'] }}</td>
                    <td>{{$vo['org_name']}}</td>
                    <td>@if($vo['status'] == 0)关闭@else开启@endif</td>
                    <td>{{ $vo['created_at'] }}</td>
                    <td>{{ $vo['updated_at'] }}</td>
                    <td>
                        <script type="text/html" id="buttons">
                            <a class="layui-btn layui-btn-xs" lay-event="more">更多 <i
                                    class="layui-icon layui-icon-down"></i></a>
                        </script>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        @include("layout.page")
    </div>
@endsection

@section('script')
    <script src="{{asset('layui/modules/xm-select.js')}}"></script>
    <script src="{{asset('js/tree/select.js')}}"></script>
    <script>
        var idx=-1;
        layui.use(['form', 'table', 'layer','xmSelect','dropdown'], function () {
            var table = layui.table;
            var form = layui.form,xmSelect = layui.xmSelect,dropdown = layui.dropdown;
            table.init("table-hide");
            let params=selectTreeParams('#index_category_id','category_id','请选择科目分类',"{{request('category_id')}}", {!! $category !!},function (data){});
            xmSelect.render(params)
            let org=selectTreeParams('#index_org_id','org_id','请选择组织机构',"{{request('org_id')}}", {!! $org !!},function (data){
                $("#index_org_code").val(data['arr'][0]['code'])
            });
            xmSelect.render(org)
            admin.paginate("{{ $data['total'] }}", "{{ $data['current_page'] }}", "{{ $data['per_page'] }}");
            table.on('tool(table-hide)', function (obj) {
                var that = this
                    , res = obj.data;
                //更多下拉菜单
                let buttons = [
                        @if(_can('admin.basic.update')){title: '编辑考场', id: 'update',type:'openLayerForm',link:"{{ route_uri(session("guard").".basic.update")}}",params:{id: res.id},set:{title:"编辑考场",method:"POST",width:"700px",height:"90%",repush:0,dome:"#update"}},@endif
                        @if(_can('admin.basic.setting')){title: '考场设置', id: 'setting',type:'link',link:"{{ route_uri(session("guard").".basic.setting")}}",params:{basic_id: res.id}},@endif
                        @if(_can('admin.basic.examindex')){title: '考试批次', id: 'exam',type:"link",link:"{{ route_uri(session("guard").".basic.examindex")}}",params:{basic_id: res.id}},@endif
                        @if(_can('admin.basic.destroy')){title: '删除考场', id: 'del',type:'tableDataDelete',link:"{{ route_uri(session("guard").".basic.destroy") }}",params:{id:res.id},set:{dome:this,title:"是否删除当前考场"}} @endif
                ]
                dropdown.render(tableButtonGroup(that,buttons))
            });
            window.getDelIds = function(){
                var checkStatus = table.checkStatus('demo')
                var arr = [];
                $.each(checkStatus['data'],function(index,value){
                    arr.push(value['id']);
                });
                layer.confirm('你确认删除吗？',{
                    btn: ['删除', '取消']
                }, function () {
                    $.ajax({
                        type: "POST",
                        url: '{{route("admin.basic.destroy")}}',
                        data:{
                            id:arr,
                            _token:'{{ csrf_token() }}'
                        },
                        success: function(res) {
                            var icon = 5;
                            if(res.error == 0){
                                icon = 6;
                            }
                            layer.msg(res.msg,{icon:icon},function(){
                                if (res.error == 0) {
                                    window.location.reload();
                                }
                            })
                        },
                    });
                }, function () {
                    layer.close();
                });
            }

        });
    </script>
    <script src="{{asset('js/layCommon.js')}}"></script>
@endsection

